package com.bblocks.pojo.dto;

import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author: Mei
 *
 * 分页条件
 * @Date: created in 2019/2/19 11:03.
 */
@Data
@Schema(description="分页对象...")
public class PageParam implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Schema(description ="页码（从1开始）")
    private Integer pageNum;
	
    @Schema(description ="每页的大小")
    private Integer pageSize;
    
    @Schema(description ="排序字段,结合order 一起使用")
    private String sort;//排序字段
    
    @Schema(description ="正反序（desc/asc）,结合sort 一起使用")
    private String order;//正反序
    
    @Schema(description ="排序（例：add_create_time desc）独立使用")
    private String orderBy;
    
    public String getOrderBy(){
        if(orderBy != null)
            return orderBy;

        if(StrUtil.isNotBlank(sort)){
            this.orderBy = sort + " " +order;
            return orderBy;
        }
        return null;
    }

    public Integer getPageNum() {
        if(pageNum==null||pageNum.equals(0)) return 1;
        return pageNum;
    }

    public Integer getPageSize() {
        if(pageSize==null||pageSize.equals(0)) return 10;
        return pageSize;
    }
}
